package com.zx.controller;


import com.zx.bean.Post;
import com.zx.dto.AjaxJson;
import com.zx.service.PostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class PostController {

    @Autowired
    private PostService postService;

    //定义一个接口
    @PostMapping("/addPost")
    public String addPost(Post post){
        return "addPost";
    }

    //定义一个删除接口
    @PostMapping("/delPost")
    public String delPost(int id){
        postService.delPost(id);
        return "delPost";
    }

    //定义一个修改的接口
    @PostMapping("/updatePost")
    public String updatePost(int id){
        postService.updatePost(id);
        return "updatePost";
    }

    //定义一个查询单个的接口
    @PostMapping("/findOnePost")
    @ResponseBody
    public AjaxJson findOnePost(int id){
        AjaxJson ajaxJson = new AjaxJson();
        Post post = postService.findOnePost(id);
        ajaxJson.put("Post",post);
        return ajaxJson;
    }

    //定义一个查询全部的接口
    @PostMapping("/findAllPost")
    @ResponseBody
    public AjaxJson findAllPost(){
        AjaxJson ajaxJson = new AjaxJson();
        postService.findAllPost();
        return ajaxJson;
    }

}
